#include<bits/stdc++.h>
using namespace std;
const int N=1003;
int n,m,a[N],b[N][N][26],d[N][N][26],ans;
char g[N][N];
signed main() {
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>g[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			for(int c=0;c<26;c++)
				b[i][j][c]=b[i-1][j][c]+(g[i][j]-'a'==c),d[i][j][c]=d[i][j-1][c]+(g[i][j]-'a'==c);
	for(int xa=1;xa<=n;xa++){
		for(int xb=xa+1;xb<=n;xb++){
			memset(a,0,sizeof(a));int cnt=0;
			for(int i=1;i<=m;i++){
				if(g[xa][i]==g[xb][i]&&b[xb][i][g[xa][i]-'a']-b[xa-1][i][g[xa][i]-'a']==xb-xa+1) a[++cnt]=i;
			}
			int tot=1;
			for(int i=2;i<=cnt;i++){
				if(g[xa][a[i]]==g[xa][a[i-1]]&&d[xa][a[i]][g[xa][a[i]]-'a']-d[xa][a[i-1]-1][g[xa][a[i]]-'a']==a[i]-a[i-1]+1&&d[xb][a[i]][g[xa][a[i]]-'a']-d[xb][a[i-1]-1][g[xa][a[i]]-'a']==a[i]-a[i-1]+1){
					ans+=tot;
					++tot;
				}
				else tot=1;
			}
		}
	}
	cout<<ans;
	return 0;
}
